//
//  GSMCViewController.m
//  VmiSJ
//
//  Created by 汪的一声就哭了！ on 2017/1/7.
//  Copyright © 2017年 汪的一声就哭了！. All rights reserved.
//

#import "GSMCViewController.h"

@interface GSMCViewController ()
@property (strong, nonatomic) IBOutlet UITextField *textField;

@end

@implementation GSMCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(saveAction)];
    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:self.fontSize]} forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem.enabled = NO;
    self.title = self.titleStr;
    self.textField.text = self.string;
    self.textField.placeholder = self.titleStr;
    [self.textField becomeFirstResponder];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChangeText) name:UITextFieldTextDidChangeNotification object:nil];
}
- (void)saveAction
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:UID,@"uid",@"reviewmaterial",@"v1", nil];
    if ([_titleStr isEqualToString:@"公司名称"]) {
        [dic setObject:self.textField.text forKey:@"company_name"];
    } else if ([_titleStr isEqualToString:@"公司简称"]) {
        [dic setObject:self.textField.text forKey:@"company_abbreviated"];
    } else if ([_titleStr isEqualToString:@"联系人"]) {
        [dic setObject:self.textField.text forKey:@"charity_name"];
    } else if ([_titleStr isEqualToString:@"手机号码"]) {
        [dic setObject:self.textField.text forKey:@"charity_telephone"];
    } else if ([_titleStr isEqualToString:@"详细地址"]) {
        [dic setObject:self.textField.text forKey:@"company_site"];
    }
    [NetRequiest handleDataWithString:HTTPLOAD dictionary:dic HUD:YES block:^(id responseObject) {
        if ([responseObject[@"code"] isEqual:@200]) {
            [self.navigationController popViewControllerAnimated:YES];
        }
        [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
    }];
}
- (void)textFieldDidChangeText
{
    if ([self.textField.text isEqualToString:self.string]) {
        self.navigationItem.rightBarButtonItem.enabled = NO;
    } else {
        self.navigationItem.rightBarButtonItem.enabled = YES;
    }
}
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
